home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / SYSMETS1.ZIP / SYSMETS1.C < prev    next >
C/C++ Source or Header  |  1991-09-16  |  3KB  |  104 lines

  1. /*----------------------------------------------------
  2.    SYSMETS1.C -- System Metrics Display Program No. 1
  3.          (c) Charles Petzold, 1990
  4.   ----------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "sysmets.h"
  8.  
  9. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  10.  
  11. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  12.             LPSTR lpszCmdline, int nCmdShow)
  13.      {
  14.      static char szAppName[] = "SysMets1" ;
  15.      HWND        hwnd ;
  16.      MSG         msg ;
  17.      WNDCLASS    wndclass ;
  18.  
  19.      if (!hPrevInstance)
  20.       {
  21.       wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  22.       wndclass.lpfnWndProc   = WndProc ;
  23.       wndclass.cbClsExtra    = 0 ;
  24.       wndclass.cbWndExtra    = 0 ;
  25.       wndclass.hInstance     = hInstance ;
  26.       wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  27.       wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  28.       wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  29.       wndclass.lpszMenuName  = NULL ;
  30.       wndclass.lpszClassName = szAppName ;
  31.  
  32.       RegisterClass (&wndclass) ;
  33.       }
  34.  
  35.      hwnd = CreateWindow (szAppName, "Get System Metrics No. 1",
  36.               WS_OVERLAPPEDWINDOW,
  37.               CW_USEDEFAULT, CW_USEDEFAULT,
  38.               CW_USEDEFAULT, CW_USEDEFAULT,
  39.               NULL, NULL, hInstance, NULL) ;
  40.      ShowWindow (hwnd, nCmdShow) ;
  41.      UpdateWindow (hwnd) ;
  42.  
  43.      while (GetMessage (&msg, NULL, 0, 0))
  44.       {
  45.       TranslateMessage (&msg) ;
  46.       DispatchMessage (&msg) ;
  47.       }
  48.      return msg.wParam ;
  49.      }
  50.  
  51. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  52.      {
  53.      static short cxChar, cxCaps, cyChar ;
  54.      char         szBuffer[10] ;
  55.      HDC          hdc ;
  56.      short        i ;
  57.      PAINTSTRUCT  ps ;
  58.      TEXTMETRIC   tm ;
  59.      switch (message)
  60.       {
  61.       case WM_CREATE :
  62.            hdc = GetDC (hwnd) ;
  63.  
  64.            GetTextMetrics (hdc, &tm) ;
  65.            cxChar = tm.tmAveCharWidth ;
  66.            cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
  67.            cyChar = tm.tmHeight + tm.tmExternalLeading ;
  68.  
  69.            ReleaseDC (hwnd, hdc) ;
  70.            return 0;
  71.  
  72.       case WM_PAINT :
  73.            hdc = BeginPaint (hwnd, &ps) ;
  74.  
  75.            for (i = 0 ; i < NUMLINES ; i++)
  76.             {
  77.             TextOut (hdc, cxChar, cyChar * (1 + i),
  78.                  sysmetrics[i].szLabel,
  79.                  lstrlen (sysmetrics[i].szLabel)) ;
  80.  
  81.             TextOut (hdc, cxChar + 18 * cxCaps, cyChar * (1 + i),
  82.                  sysmetrics[i].szDesc,
  83.                  lstrlen (sysmetrics[i].szDesc)) ;
  84.  
  85.             SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
  86.  
  87.             TextOut (hdc, cxChar + 18 * cxCaps + 40 * cxChar,
  88.                  cyChar * (1 + i), szBuffer,
  89.                  wsprintf (szBuffer, "%5d",
  90.                   GetSystemMetrics (sysmetrics[i].nIndex))) ;
  91.  
  92.             SetTextAlign (hdc, TA_LEFT | TA_TOP) ;
  93.             }
  94.  
  95.            EndPaint (hwnd, &ps) ;
  96.            return 0 ;
  97.  
  98.       case WM_DESTROY :
  99.            PostQuitMessage (0) ;
  100.            return 0 ;
  101.       }
  102.  
  103.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  104.      }